package com.platform.service.impl;

import com.platform.dao.ComboboxDao;
import com.platform.domain.TbSysRole;
import com.platform.domain.result.ComboboxData;
import com.platform.service.ComboboxService;
import com.platform.service.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: wangyanginfo
 * Date: 12-9-11
 * Time: 下午3:44
 * To change this template use File | Settings | File Templates.
 */
@Service("comboboxService")
public class ComboboxServiceImpl implements ComboboxService {

    @Resource
    private ComboboxDao comboboxDao;

    @Resource
    private RoleService roleService;

    /**
     * 查询下拉框结构的角色信息
     *
     * @param userId 用户ID
     * @return 机构信息列表
     */
    @Override
    public List<ComboboxData> queryComboboxRoles(String userId) throws Exception {
        List<TbSysRole> list_role = roleService.queryRoleByUserId(userId);
        List<ComboboxData> list_combobox = new ArrayList<ComboboxData>();
        for (TbSysRole role : list_role) {
            ComboboxData combobox = new ComboboxData();
            combobox.setId(role.getRoleId());
            combobox.setText(role.getRoleName());
            list_combobox.add(combobox);
        }
        return list_combobox;
    }

    /**
     * 查询下拉框结构的机构信息
     *
     * @param superiorDeptId 上级机构ID
     * @return 机构信息列表
     */
    @Override
    public List<ComboboxData> queryComboboxDepts(String superiorDeptId) throws Exception {
        return comboboxDao.queryDepts(superiorDeptId);
    }

    /**
     * 根据字典类型查询字典信息
     *
     * @param classId 字典类型
     * @return 字典信息列表
     */
    @Override
    public List<ComboboxData> queryComboboxDicts(String classId) throws Exception {
        return comboboxDao.queryDicts(classId);
    }
}
